﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VNEYEModel;

public partial class Account_ServiceDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            string id = Request.QueryString["id"];
            if (id == "" || id == null)
            {
                Response.Redirect("Service.aspx");
            }
            else
            {
                Disable();
                var vn = new VNEYEEntities();
                var result = vn.getServiceById(int.Parse(id)).ToList();
                foreach (var service in result)
                {
                    txtNam.Text = service.S_Name;
                    txtDesc.Text = service.S_Description;
                    txtContent.Text = service.S_Content;
                    bool? status = service.STATUS;
                    if(status==true)
                    {
                        drdStatus.SelectedIndex = 0;
                    }
                    else
                    {
                        drdStatus.SelectedIndex = 1;
                    }
                }
            }
        }
    }
    public void Disable()
    {
        txtNam.Enabled = false;
        txtDesc.Enabled = false;
        txtContent.Enabled = false;
        drdStatus.Enabled = false;
    }
    public void Enable()
    {
        txtNam.Enabled = true;
        txtDesc.Enabled = true;
        txtContent.Enabled = true;
        drdStatus.Enabled = true;
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        if(btnEdit.Text=="Sửa Dịch Vụ")
        {
            Enable();
            btnEdit.Text = "Chấp Nhận";
        }
        else
        {
            string name = txtNam.Text;
            string description = txtDesc.Text;
            string content = txtContent.Text;
            bool status = false;
            if(drdStatus.SelectedIndex==0)
            {
                status = true;
            }
            var vn = new VNEYEEntities();
            vn.updateServiceById(int.Parse(Request.QueryString["id"]), name, description, content, status);
            lblInfo.Text = "Thay Đổi Dịch Vụ Thành Công";
            Disable();
            btnEdit.Text = "Sửa Dịch Vụ";
        }
    }
}